﻿''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Public Class expressionFiltreBDD
    Protected _corresp As Correspondance
    Protected _operateur As String
    Protected _valeur As String
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New(ByVal corresp As Correspondance, _
                   ByVal operateur As operateurFiltreBDD, _
                   ByVal valeur As String)
        _corresp = corresp
        _operateur = OperateurAsString(operateur)
        _valeur = valeur
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Property valeur() As String
        Get
            Return _valeur
        End Get
        Set(ByVal value As String)
            If _valeur <> value Then
                _valeur = value
                'Lorsque la valeur est modifiée, le traitement contenant le filtre doit être modifié
                RaiseEvent valeurAchange(Me, Nothing)
            End If
        End Set
    End Property
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Friend Function genereSQL() As String
        Dim result As String = ""
        Return _corresp.codeSQLSELECT(False) & _operateur & _valeur
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Function OperateurAsString(ByVal op As operateurFiltreBDD)
        Dim result As String = ""
        Select Case op
            Case operateurFiltreBDD.DifferentDe
                result = "<>"
            Case operateurFiltreBDD.Egal
                result = "="
            Case operateurFiltreBDD.InferieurOuEgal
                result = "<="
            Case operateurFiltreBDD.InferieurStrictement
                result = "<"
            Case operateurFiltreBDD.SuperieurOuEgal
                result = ">="
            Case operateurFiltreBDD.SuperieurStrictement
                result = ">"
        End Select
        Return result
    End Function
    Public Event valeurAchange As EventHandler
End Class
